﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Messaging;

namespace _15_MSMQSender
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void mSend_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < 1000000;i++)
                m_Queue.Send(mText.Text);

            MessageBox.Show("Done!");
        }

        private void m_SendTransaction_Click(object sender, EventArgs e)
        {
            MessageQueueTransaction transaction;
            transaction = new MessageQueueTransaction();
            transaction.Begin();
            m_QueueTransaction.Send(mText.Text, transaction);

            //Object a = null;

            //Console.WriteLine(a.ToString());

            transaction.Commit();
        }

        private void m_Queue_ReceiveCompleted(object sender, ReceiveCompletedEventArgs e)
        {

        }

        private void mSendXML_Click(object sender, EventArgs e)
        {
            System.Messaging.Message msg = new System.Messaging.Message();
            msg.Body = mText.Text;
            msg.Formatter = new XmlMessageFormatter();
            //msg.EncryptionAlgorithm = EncryptionAlgorithm.Rc2;
           // m_QueueXML.EncryptionRequired = EncryptionRequired.Body;
            m_QueueXML.Send(msg);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            MessageQueue queue_src = null;

            if (MessageQueue.Exists(@".\Private$\SrcQueue"))
                queue_src = new MessageQueue(@".\Private$\SrcQueue");
            else queue_src = MessageQueue.Create(@".\Private$\SrcQueue");


            System.Messaging.Message msg = new System.Messaging.Message();
            msg.Body = mText.Text;
            queue_src.Send(msg);


        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }
}